package com.substation.ui.adapter;

import android.app.Activity;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.greenentity.Photo;
import com.jessewu.library.SuperAdapter;
import com.jessewu.library.view.ViewHolder;
import com.net.Contants;
import com.previewlibrary.GPreviewBuilder;
import com.substation.R;
import com.substation.ui.utils.XUtils;

import java.io.File;
import java.util.List;

/**
 * Created by admin on 2018/5/16.
 */

public class DefectImageAdapter extends SuperAdapter<Photo> {

    private Activity context;
    private List<Photo> datas;

    public DefectImageAdapter(int layoutId) {
        super(layoutId);
    }

    public DefectImageAdapter(Activity context, List<Photo> datas) {
        this(R.layout.content_imge_horizontal);
        this.context = context;
        this.datas = datas;
    }

    @Override
    public void bindView(ViewHolder viewHolder, Photo s, final int i) {
        if (new File(s.getPhAdd()).exists()) {
            Glide.with(context).load(s.getPhAdd()).into((ImageView) viewHolder.getView(R.id.imageView));
        } else {
            Glide.with(context).load(Contants.getPicUrl(context, s.getPhUrl())).into((ImageView) viewHolder.getView(R.id.imageView));
        }
        viewHolder.getView(R.id.imageView).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                GPreviewBuilder.from(context)
                        .setData(XUtils.Photo2String(datas))
                        .setCurrentIndex(i)
                        .setSingleFling(false)//是否在黑屏区域点击返回
                        .setDrag(false)//是否禁用图片拖拽返回
                        .setType(GPreviewBuilder.IndicatorType.Number)//指示器类型
                        .start();//启动
            }
        });
    }
}
